//
//  BrandController.m
//  i优购商城
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "BrandController.h"
#import "HttpRequestManager.h"
#import "UIImageView+AFNetworking.h"
#import "BrandCell.h"
#import "Product.h"
#import "BigCell.h"
#import "BrandView.h"
#import "ITEM.h"
#import "ListController.h"
@interface BrandController ()<UIScrollViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    NSMutableArray*_dataArry;
    NSMutableArray*_nameA;
    int _num;
  
}
@property (weak, nonatomic) IBOutlet UIScrollView *myScrollView;
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;



@end

@implementation BrandController

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        _dataArry=[[NSMutableArray alloc]init];
        _num=0;
        _nameA=[[NSMutableArray alloc]init];
       
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadDataFromNet];
    
}

-(void)loadDataFromNet
{
    for (_num=0; _num<10; _num++) {
    [[HttpRequestManager shareInstance]getBrandDataBypage:_num Success:^(id responseobject) {
        [_dataArry addObject:responseobject];
        [_myCollectionView reloadData];
    } Failure:^(NSError *error) {
        NSLog(@"请求数据失败,error===%@",error);
    }];
    }
    
}


-(void)initScrovlliew
{

    _myScrollView.contentSize=CGSizeMake(55*_nameA.count+5, 0);
    for (int i=0; i<_nameA.count; i++) {
        UIButton*Btn=[UIButton buttonWithType:UIButtonTypeCustom];
        Btn.frame=CGRectMake((50+5)*i+5, 0, 50, 30);
        [Btn setTitle:_nameA[i] forState:UIControlStateNormal];
        Btn.tintColor=[UIColor whiteColor];
        Btn.titleLabel.font=[UIFont systemFontOfSize:10];
        [Btn setBackgroundImage:[UIImage imageNamed:@"02_gw_btn"] forState:UIControlStateNormal];
        [_myScrollView addSubview:Btn];
        
    }

}



#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
  
    return 10;
}


-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BigCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"BigCell" forIndexPath:indexPath];
     cell.urlString =@"";
    if (_dataArry.count>0) {
         NSDictionary*dic=_dataArry[indexPath.item];
        cell.dataArry=dic[@"brands_wall"][0][@"value"];
        cell.iconStr=dic[@"advert_banner"][0][@"adImg"];
        [cell.ScollectionView reloadData];
        cell.myBlock=^(ITEM*item){
            [self performSegueWithIdentifier:@"pushToList" sender:item];
        
        
        };
   
     
    }
    return cell;
    

}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(_myCollectionView.frame.size.width, _myCollectionView.frame.size.height);
    
    
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"pushToList"]) {
        
        ListController*list=segue.destinationViewController;
        list.item=sender;
    }


}



@end
